package ac.qnlm.listener;

import ac.qnlm.antlr.CPP14BaseListener;
import ac.qnlm.antlr.CPP14Parser;
import ac.qnlm.util.Utility;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.tree.ParseTree;
import org.antlr.v4.runtime.tree.ParseTreeProperty;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class secondTraverseListener extends CPP14BaseListener {

    ParseTreeProperty<String> parsetree;
    public String getclass(ParseTree ctx) {
        return parsetree.get(ctx);
    }

    public void setclass(ParseTree ctx, String s) {
        parsetree.put(ctx, s);
    }

    private static Logger mLogger = LogManager.getLogger(firstTraverseListener.class.getName());
    public secondTraverseListener(ParseTreeProperty<String> tree, Utility utility, CommonTokenStream tokens) {
        //super();
        this.parsetree = tree;
    }

    @Override public void exitTranslationunit(CPP14Parser.TranslationunitContext ctx)
    {
        StringBuilder buftree = new StringBuilder();
        if(ctx.declarationseq()!=null) {
            //String args = getclass(ctx.declarationseq());
            String args = ctx.declarationseq().getText();
            buftree.append(args);
            setclass(ctx, buftree.toString());

            mLogger.info("enterTranslationunit final\t\n" + args);
        }
    }
}
